package com.cola.springmvc.converter;

import com.cola.springmvc.pojo.User;
import org.springframework.core.convert.converter.Converter;

/**
 * @Grup:com.cola.springmvc.converter
 * @Auther:cola
 * @Data:2021/5/1-2021-05-18:28
 * @version:1.0
 */
public class UserConverter implements Converter<String , User> {
    @Override
    public User convert(String source) {
        System.out.println("User格式转换器");
        if (source != null) {
            String[] split = source.split("-");
            if (split != null &&split.length==3) {
                String username=split[0];
                Integer age=Integer.parseInt(split[1]);
                String eamil=split[2];

                User user =new User();
                user.setUsername(username);
                user.setAge(age);
                user.setEmail(eamil);
                return user;
            }
        }
        return null;
    }
}
